/**
 * 
 */
package org.statewalker.parser.wiki.tokenizer.block;

import org.statewalker.parser.wiki.grammar.WikiBlockDict;
import org.statewalker.tokenizer.AbstractTokenizer;
import org.statewalker.tokenizer.CharStream;
import org.statewalker.tokenizer.ITokenizer;
import org.statewalker.tokenizer.StreamToken;
import org.statewalker.tokenizer.CharStream.Marker;
import org.statewalker.tokenizer.CharStream.Pointer;

public class TableTokenizer extends AbstractTokenizer {

    private ITokenizer fCellTokenizer;

    public TableTokenizer(ITokenizer cellTokenizer) {
        this(cellTokenizer, WikiBlockDict.TABLE);
    }

    public TableTokenizer(ITokenizer cellTokenizer, String key) {
        super(key);
        fCellTokenizer = cellTokenizer;
    }

    public StreamToken read(CharStream stream) {
        Pointer pointer = stream.getPointer();
        if (pointer.column > 0)
            return null;
        Marker marker = stream.markPosition();
        try {
            StreamToken result = null;
            if (fCellTokenizer.read(stream) != null) {
                result = newToken(pointer, pointer, "");
            }
            return result;
        } finally {
            marker.close(true);
        }
    }
}